package com.xc.file.web.rest.open;

import com.xc.api.basic.BasicApi;
import com.xc.config.aspect.AspectConstants;
import com.xc.core.bean.SignBean;
import com.xc.core.dto.SignDto;
import com.xc.file.entity.FolderEntity;
import com.xc.file.service.FolderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>开放接口，文件夹管理</p>
 *
 * @author xc
 * @version v1.0.0
 */
@Api(tags = "开放接口，文件夹管理")
@RestController
public class OpenFolderRest {
    @Autowired
    private BasicApi basicApi;
    @Autowired
    private FolderService folderService;
    @Autowired
    private AspectConstants aspectConstants;

    @ApiOperation(value = "删除文件夹", notes = "开放接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "文件夹路径", name = "path", paramType = "query", required = true)
    })
    @DeleteMapping("/open/folder")
    public void deleteOpenFolder(@ModelAttribute SignBean signBean, @RequestParam String path) {
        signBean.setAuthorityCode("deleteOpenFolder");
        signBean.setMyAppId(aspectConstants.getAppId());
        SignDto signDto = basicApi.verifySign(signBean);
        FolderEntity folderEntity = folderService.getFolderByPath(signDto.getUserId(), path);
        if (folderEntity != null) {
            List<String> list = new ArrayList<>();
            list.add(signDto.getUserId());
            folderService.deleteUserFolder(list, folderEntity.getId());
        }
    }
}
